<?php
/**
 * ClassName: TreatmentService
 * Description:
 * @Author 周昌
 * @Create 2023/11/17 16:19
 */

namespace service\admin;


use service\BaseService;

class TreatmentService extends BaseService
{
    protected static $model='model\TreatmentModel';

    //列表数据
    public static function getAjaxData($where)
    {
        $table = self::$model::order('id desc');
        $adminInfo=self::getAdminInfo();
        return self::tableJsonData($table, $where, function ($data)use($adminInfo){
            if($adminInfo['role']==1){
                $data['treatment_cate_name']=TreatmentCateService::getNameByKey($data['treatment_cate_id']);
            }else{
                $data['treatment_cate_name']=TreatmentCateService::getNameByKey($data['treatment_cate_id'],['hospital_id'=>$adminInfo['hospital_id']]);
            }
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],'','id,name','id','hospital_key_name'):'';
            return $data;
        });
    }

    // 组装设置绩效时数据
    public static function getTreatmentList(){
        $hospitalId = self::getUserHospitalId();
        $list = self::$model::getList(['hospital_id'=>$hospitalId,'status'=>1],'*','treatment_cate_id asc');
        $outlist = [];
        foreach($list as $k=>$v){
            $cateId = $v['treatment_cate_id'];
            if(isset($outlist[$cateId])){
                $outlist[$cateId]['list'][] = $v;
            }else{
                $outlist[$cateId]['cate_name'] = TreatmentCateService::getNameByKey($cateId);
                $outlist[$cateId]['list'] = [];
                $outlist[$cateId]['list'][] = $v;
            }
        }
        return $outlist;
    }



}